<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="ee.nutilovi.praktikaportaal.tools.CryptoTools"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./static/css/style.css">
<script language="javascript" type="text/javascript" src="./static/js/jquery-2.0.3.js"></script>
<script language="javascript" type="text/javascript" src="./static/js/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript" src="./static/js/javascript.js"></script>
</head>
<body>
	<%
		Cookie[] cookies = request.getCookies();
		String username = null;
		String userHash = null;
		boolean userCookieFound = false;
		String admin = null;
		String adminHash = null;
		boolean isAdmin = false;

		if (cookies != null) {
			for (Cookie c : cookies) {
				if (c.getName().equals("userId")) {
					username = c.getValue().split("\\|")[0];
					userHash = c.getValue().split("\\|")[1];
					if (userHash.equals(CryptoTools.hashUser(username))) {
						userCookieFound = true;
					}
				} else if (c.getName().equals("isAdmin")) {
					admin = c.getValue().split("\\|")[0];
					adminHash = c.getValue().split("\\|")[1];
					if (adminHash.equals(CryptoTools.hashUser(admin))) {
						isAdmin = Boolean.valueOf(admin);
					}
				}
			}
		}
	%>
	<div id="header">
		<div id="header-container">
			<div id="logo-container">
				<img id="logo" src="./static/img/logo_1.png" alt="logo">
			</div>
			<div id="login-container">
				<%
					if (userCookieFound) {
				%>
				<p>Sisse logitud kasutaja: <%= username %></p><br>
				<a href="/logout">Logi välja</a>
				<%
					} else {
				%>
				<form action="/login" method="post">
					<input type="text" name="username"><br>
					<input type="password" name="password"><br>
					<input type="submit" value="Logi Sisse"></input><br>
				</form>
				<a href="/register">Registreeru kasutajaks</a>
				<%
					}
				%>				
			</div>
		</div>
	</div>

	<div id="nav">
		<ul id="navbar">
			<li id="index"><a href="/""><span>Pealeht</span></a></li>
			<li id="companies"><a href="/companies"><span>Ettevõtted</span></a></li>
			<li id="offers"><a href="/offers"><span>Tööpakkumised</span></a></li>
			<li id="admin"><a href="/admin"><span>Administreerimine</span></a></li>
		</ul>
		<ul id="sub-navbar">
			<li class="active"><a href="#"><span>Element1</span></a></li>
			<li><a href="#"><span>Element2</span></a></li>
			<li><a href="#"><span>Element3</span></a></li>
			<li><a href="#"><span>Element4</span></a></li>
		</ul>
	</div>

</body>
</html>